<template>
	<view class="">
		<video @error="videoErro" id="myVideo" :show-center-play-btn="false" :show-play-btn="false"
					 :show-progress="false" :style="{height:playHeight+'px'}" :custom-cache="false" style="width: 100%;"
					 @play="videoPlay"  :muted="videMuted" :autoplay="videAoutoplay" />
		<video  id="remoteAudio" :show-center-play-btn="false" :show-play-btn="false"
						:show-progress="false" style="position: fixed;left: 0;top: 0;width: 1rpx;height:1rpx;opacity: 0"
						:muted="false" :autoplay="true" />
		<view style="width: 100%;margin:50rpx 0 0 0;">
			播放地址输入栏👇
			<textarea style="background-color:black; color: #FFFFFF;height: 150rpx;width: 100%;" name="" id=""  maxlength="-1" v-model.trim="playUrlInput"></textarea>
		</view>
		<view style="display: flex;align-items: center;justify-content: center;">
			<button class="block radius-btn" style="width: 300rpx" @tap="call" type="operation" :disabled="!playUrlInput">开始视频</button>
			<button class="block radius-btn" style="width: 300rpx" @tap="hangup" type="primary" :disabled="hangupVideoButton">挂断视频</button>
		</view>
		<view style="width: 100%">
			对讲地址输入栏👇
			<view >
				<textarea style="background-color:black; color: #FFFFFF;height: 150rpx;width: 100%;" name="" id=""  maxlength="-1" v-model.trim="talkUrlInput"></textarea>
			</view>
		</view>
		<view style="display: flex;align-items: center;justify-content: center;">
			<button class="block radius-btn" style="width: 300rpx" @tap="setTalk" type="operation" :disabled="!talkUrlInput">开始对讲</button>
			<button class="block radius-btn" style="width: 300rpx" @tap="setTalkDisable" type="primary" :disabled="stopTalkButton">结束对讲</button>
		</view>
	</view>
</template>

<script>
	import {webrtc} from "./mixins/webrtc";
	let constant = getApp().globalData.constant;
	export default {
		mixins:[webrtc],
		data() {
			return {
				list: {
					number: 98
				},
				device: { // 设备对象
					deviceName: ''
				},
				deviceList: [], // 缓存列表
				isCache: false, // 是否存在缓存
				timer: null, //保活定时器
				keepAliveCount: 0, // 保活次数迭代变量
				/** 推流相关 */
				videoContext: {}, // 视频对象
				url: '',
				stream: '1', // 高清还是标清（标清用: 1 表示， 高清用: 0 表示）
				streamText: '标清', // 高清还是标清文本说明
				streamTextIcon: 'FHD', // 高清还是标清icon
				isFullScreen: false, //是否全屏
				isShowBar: true, // 显示隐藏bar控条
				isLoading: true, //加载中
				loadingText: '正在获取视频播放地址...', //加载中文字说明
				time: 3, // 时间间隔
				isMute: true,
				tempIsMute: false,
				isClose: false,
				isShowHD: false,
				hdText: '标清',
				isHd: false,
				show: false,
				isPush: false,
				isLoginSuccess: true,
				isLogin: false,
				navTitle: '',
				bl: null,
				bal: null,
				hideType: 1,
				isLogout: false,
				isShowLock: true,
				isShowPlayBtn: false,
				isStartPlay: false,
				deviceStatus: '',
				pathType: 1,
				disConnectCount: 0,
				isShowDeepSleepModal: false,
				isShowLightSleepModal: false,
				LightSleepStatus: false,
				DeepSleepStatus: false,
				isFirstFrame: false,
				playType: 0,
				isShowBg: true,
				noDataStatus: false,
				isSupportSpeak: false,
				playOrNot: null,
				clickTalkStatus: false,
				isSupportVideoTalk: false, //是否支持双向视频对讲
				powerSavingMode: {}, //省电模式

				videAoutoplay: true, //自动播放
				videMuted: true, //静音
				videoPlayUrl: '',
				playHeight: '',

			// 	webrtc 相关
				startVideoButton:true,
				hangupVideoButton:true,
				startTalkButton:true,
				stopTalkButton:true
			};
		},
		computed: {
		},
		onLoad(options) {

		},
		onShow() {
			this.getClineHeight()
		},
		onHide() {
			uni.hideLoading()
		},
		onUnload() {
			uni.hideLoading()
			this.closeAllLinks(1)
		},
		methods: {
			setTalk() {
				// this.getTalk();
				this.setTalkEnable()
			},
			getClineHeight() {
				uni.getSystemInfo({
					success: (res => {
						this.playHeight = res.windowHeight - 400
					})
				});
			},
			videoErro(e) {
				console.log(e, '播放错误')
				uni.hideLoading()
				if (e.type == 'error' && this.videoPlayUrl) {
					uni.showModal({
						title: this.$t('General.device.title'),
						content: this.$t('General.device.tip6'),
						confirmColor: '#1AC0BA',
						showCancel: false,
						success: (res) => {}
					});
				}
			},
			videoPlay(e) {
				setTimeout(()=>{
					uni.hideLoading();
					uni.showToast({
						title: this.$t('General.device.tip7'),
						icon: 'none'
					})
				},800)
				console.log(e, '播放成功')
			},
		}
	};
</script>

<style>
</style>